#include <stx/test/test.hpp>

TEST_CASE (core_time)
{
    constexpr auto ts_mid   = std::time_t(1639980820uz);
    constexpr auto ts_start = ts_mid - 10000uz * 3600uz;
    constexpr auto ts_end   = ts_mid + 50000uz * 3600uz;

    LOOP_N (10_K)
    {
        auto ts_rnd = static_cast<std::time_t>(rand(ts_start, ts_end));

        auto const tm = std::gmtime(&ts_rnd);
        auto const tp = SystemClock::from_time_t(ts_rnd);
        auto const dt = getDateTime(tp);

        CHECK(Number(tm->tm_year + 1900) == dt.getYear());
        CHECK(Number(tm->tm_mon + 1) == dt.getMonth());
        CHECK(Number(tm->tm_mday) == dt.getDay());
        CHECK(Number(tm->tm_hour) == dt.getHour());
        CHECK(Number(tm->tm_min) == dt.getMinute());
        CHECK(Number(tm->tm_sec) == dt.getSecond());

        auto ts1 = Number(std::time(nullptr));
        auto ts2 = getTimestamp<Seconds>();
        CHECK(ts1 == ts2 || ts1 + 1 == ts2);
    }
}